﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using dienthoaiminhanh.Business;
using dienthoaiminhanh.Data;

namespace dienthoaiminhanh.MyControll
{
    public partial class uMenu : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            loadMenu();
        }
        #region[Loadmenu]
        public void loadMenu()
        {
            string Cha = "";
            string Con = "";
            List<Data.Page> list = PageService.Page_GetByTop("10", "Active=1 and LEN(Level)=5", "Ord");
            if (list.Count > 0)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    List<Data.Page> listSub = PageService.Page_GetBySub(list[i].Level);
                    if (listSub.Count > 0)
                    {
                        Cha += "<li><a href=\"/" + list[i].Link + "\" rel=\"ddsubmenu" + i + 1 + "\">" + list[i].Name + "</a></li>";
                        Con += "<ul id=\"ddsubmenu" + i + 1 + "\" class=\"ddsubmenustyle\">";
                        for (int j = 0; j < listSub.Count; j++)
                        {
                            List<Data.Page> listSub1 = PageService.Page_GetBySub(listSub[j].Level);
                            if (listSub1.Count > 0)
                            {
                                Con += "<li><a href=\"/" + listSub[j].Link + "\">" + listSub[j].Name + "</a>";
                                Con += "<ul>";
                                for (int k = 0; k < listSub1.Count; k++)
                                {
                                    Con += "<li><a href=\"/" + listSub1[k].Link + "\">" + listSub1[k].Name + "</a></li>";
                                }
                                Con += "</ul>";
                                Cha += "</li>";
                            }
                            else
                            {
                                Con += "<li><a href=\"/" + listSub[j].Link + "\">" + listSub[j].Name + "</a></li>";
                            }
                        }
                        Con += "</ul>";
                    }
                    else
                    {
                        Cha += "<li><a href=\"/" + list[i].Link + "\">" + list[i].Name + "</a></li>";
                    }
                }
            }
            ltrMenu.Text = Cha;
            ltrMenusub.Text = Con;
            list.Clear();
            list = null;
        }
        #endregion
    }
}